﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

    Rigidbody rb;

    public float speed = 30.0f;

    Vector3 distance;

    public int count = 0, now_target = 0;

    List<Vector3> targets = new List<Vector3>();
    
    void addTarget(Vector3 vector)
    {
        targets.Add(vector);
        count++;
    }

    // Use this for initialization
    void Start ()
    {
        rb = GetComponent<Rigidbody>();
        addTarget(new Vector3(-10, 0, 0));
        addTarget(new Vector3(-10, 0, 10));
        addTarget(new Vector3(-20, 0, 10));
        addTarget(new Vector3(-20, 0, 0));
    }
	
	// Update is called once per frame
	void Update () {
        distance = targets[now_target] - rb.position;
        if (distance.magnitude>=1.0f)
        {
            rb.AddForce(distance.normalized * speed);
        }
        else
        {
            now_target = (now_target + 1) % count;
            Debug.Log("get！");
        }
    }
}
